<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no" />
  <title>03-点名系统.html</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      padding: 20px;
    }

    h1 {
      padding: 10px;
      background-color: #9acd32;
      color: purple;
      margin: 10px 0;
    }

    button {
      width: 100px;
      height: 50px;
      border-radius: 25px;
      background-color: #9acd32;
      color: #fff;
      border: none;
      font-size: 20px;
    }

    ul {
      list-style: none;
      display: flex;
      flex-wrap: wrap;
    }

    li {
      width: 100px;
      height: 40px;
      background-color: #000;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 10px;
    }

    /* 在随机抽取的过程中被选中的 */
    .active {
      background-color: #9acd32;
      color: #fff;
    }

    /* 确定下来了 最终被选中 */
    .select {
      background-color: palevioletred;
      color: #fff;
    }
  </style>
</head>

<body>
  <h1>被选中的小伙伴们:</h1>
  <button>开始</button>
  <ul>
    <!-- <li class="">张三</li>
    <li class="active">李四</li>
    <li class="select">王五</li> -->
  </ul>
  <script>
    let arr = [
      "董铠诚",
      "周宇轩",
      "符高满",
      "郑遥",
      "梅婷婷",
      "张成",
      "黎扬达",
      "陈可莹",
      "袁震霆",
      "余建泉",
      "李豪",
      "苏雄根",
      "李知锋",
      "李燕",
      "钟文龙",
      "王益滔",
      "岑业荣",
      "林丽转",
      "向虹霓",
      "朱志通",
      "黄敬儒",
      "吴科霖",
      "蔡亲行",
      "梁湛枝",
      "郑俊鑫",
      "廖任登",
      "张宜",
      "陈学文",
      "吴烜嘉",
      "莫远鹏",
      "曹梦飞",
      "许文龙",
      "赖秋燕",
      "李明",
      "苏文彬",
      "郭嘉豪",
      "陈冬桦",
      "蒋林池",
      "李耀艳",
      "王友滨",
      "杨青松",
      "陈桂玲",
      "钟俊源",
      "王木旺",
      "李佳惠",
      "李春丽",
      "黎长玲",
      "杨鑫隆",
      "王露",
      "赖嘉晖",
      "吴道纪",
      "何卓杭",
    ]
    let newArr = []

    const ul = document.querySelector('ul')
    localStorage.setItem('arr', JSON.stringify(arr))

    newArr = JSON.parse(localStorage.getItem('arr'))


    let str = newArr.map(function (item, index) {
      return `<li class="">${item}</li>`
    })

    ul.innerHTML = str.join('')







    const btn = document.querySelector('button')

    btn.addEventListener('click', function () {

      let num = 0

      let all = document.querySelectorAll('ul li:not(.select)')

      let h1 = document.querySelector('h1')

      let timer = setInterval(function () {

        if (num < 5) {
          num++
          let random = Math.floor(Math.random() * all.length)
           i = random

          document.querySelector('.active') && document.querySelector('.active').classList.remove('active')

          all[random].classList.add('active')
        } else {

          clearInterval(timer)

          all[i].classList.add('select')  

          
          h1.innerHTML += `${all[i].innerText}  `
        }
      }, 100)

    
    })

  </script>
</body>

</html>